package com.ytjj.test01;

import com.alibaba.excel.EasyExcelFactory;
import com.alibaba.excel.metadata.Sheet;
import com.google.gson.Gson;
import com.kuaidi100.sdk.api.QueryTrack;
import com.kuaidi100.sdk.request.QueryTrackParam;
import com.kuaidi100.sdk.request.QueryTrackReq;
import com.kuaidi100.sdk.response.QueryTrackResp;
import com.kuaidi100.sdk.utils.PropertiesReader;
import com.kuaidi100.sdk.utils.SignUtils;
import com.ytjj.common.constants.QueueConstants;
import com.ytjj.common.dto.mqdto.SmsDto;
import com.ytjj.common.exception.ApiException;
import com.ytjj.qmyx.admin.service.adapay.AdaPayService;
import com.ytjj.qmyx.admin.QmyxAdminApplication;
import com.ytjj.qmyx.admin.annotation.oplog.OperationLogAop;
import com.ytjj.qmyx.admin.model.vo.MobileVO;
import com.ytjj.qmyx.admin.service.*;
import com.ytjj.qmyx.admin.service.bigdata.AdsExposeService;
import lombok.extern.slf4j.Slf4j;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner;
import org.springframework.util.CollectionUtils;

import javax.annotation.Resource;
import java.io.*;
import java.util.List;


@SpringBootTest(classes = QmyxAdminApplication.class)
@RunWith(SpringRunner.class)
@Slf4j
public class Demo {

    @Resource
    private UserService userService;

    @Resource
    private OperationLogAop operationLogAop;

    @Resource
    private AdsExposeService adsExposeService;

    @Resource
    private OrdersService ordersService;

    @Autowired
    private UsersWithdrawalRecordService usersWithdrawalRecordService;

    @Autowired
    private AdaPayService adaPayService;

    @Test
    public void transferAlipay() {
//        usersWithdrawalRecordService.transferByAlipay("PAY202109232053111234213",
//                "0.01", "18873058010", "ALIPAY_LOGON_ID", "姜康");
    }

    @Test
    public void seeUser(){
//        adsExposeService.scheduleTask();
    }

    @Test
    public void seeLog(){

        QueryTrack queryTrack = new QueryTrack();
        QueryTrackReq queryTrackReq = new QueryTrackReq();
        QueryTrackParam queryTrackParam = new QueryTrackParam();
        queryTrackParam.setCom("yunda");
        queryTrackParam.setNum("432986430224864");
        queryTrackParam.setPhone("13786028713");
        queryTrackReq.setParam(queryTrackParam);
        queryTrackReq.setCustomer(PropertiesReader.get("customer"));
        queryTrackReq.setSign(SignUtils.sign(new Gson().toJson(queryTrackParam) + PropertiesReader.get("key") + PropertiesReader.get("customer")));
        QueryTrackResp resp = queryTrack.queryTrack(queryTrackReq);
        resp.getData();
    }
    @Test
    public void see(){
//        ordersService.getChildOrderDetail("G202010271909339867806","Q123");
    }

    @Autowired
    private RabbitTemplate rabbitTemplate;

    @Test
    public void sendSms() {
        String filePath = "D://mobile.xlsx";
        File file=new File(filePath);
        if(!file.exists()){
            throw new ApiException("文件不存在!");
        }
        Sheet sheet = new Sheet(1, 0, MobileVO.class);
        try {
            List<Object> list = EasyExcelFactory.read(new BufferedInputStream(new FileInputStream(file)), sheet);
            if (CollectionUtils.isEmpty(list)) {
                return;
            }

            String account = "xxx";
            String password = "xxxx";
            String message = "【XXXX优品2】尊敬的会员，您好！由于业务变更，部分链接已失效；现查询订单、物流或咨询客服，请前往<XXXX优品2>公众号查询。给您造成不便，敬请谅解!";
            list.stream().forEach(item -> {
                MobileVO mobileVO = (MobileVO) item;
                SmsDto dto = new SmsDto();
                dto.setType(7);
                dto.setPhone(mobileVO.getMobile());
                rabbitTemplate.convertAndSend(QueueConstants.SMS_QUEUE, dto);

                String[] phones = {mobileVO.getMobile()};
//                String result = EncryptUtil.sendSanTong("http://www.dh3t.com/json/sms/Submit", account, password, phones, message);
//                log.info("===三通返回结果：{}，{}", mobileVO.getMobile(), result);
            });
        } catch (FileNotFoundException e) {
            System.out.println();
        }
    }


}
